/* api */
import { getInfos } from '@src/api/LinkcApi'
/* hooks */
import { useFetchResult } from '@hooks/useFetch'
/* vue */
import { computed, ComputedRef } from 'vue'

export function usePortal() {
  const linkcInfos: any = useFetchLinkcInfos()
  
  const linkcInfosName: ComputedRef<string> = computed(() => linkcInfos.value?.baseInfo?.name || '')
  
  function updateLinkcInfosName (name: string) {
    linkcInfos.value.baseInfo.name = name
  }

  return [linkcInfos, linkcInfosName, updateLinkcInfosName]
}

export function useFetchLinkcInfos(): any {
  
  let [data, callback] = useFetchResult<any, any>(async () => {
    return getInfos()
  }, {})
  
  callback()
  
  return data
}
